package com.system.web.servlet;

import com.alibaba.fastjson.JSON;
import com.system.dao.DrugDao;
import com.system.dao.PersonDao;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AutoCompleteServlet extends BaseServlet
{
  private static final long serialVersionUID = 2641762103747818320L;

  public void getDrugList(HttpServletRequest request, HttpServletResponse response)
  {
    try
    {
      DrugDao dao = new DrugDao();
      String keyword = request.getParameter("q");
      keyword = new String(keyword.getBytes("iso8859-1"),"utf-8");
      String campus = request.getParameter("campus");
      List list = dao.getDrugAutoData(keyword, campus);
      writeJsonReuslt(response, list != null ? JSON.toJSONString(list) : "");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void getPersonList(HttpServletRequest request, HttpServletResponse response)
  {
    try {
      PersonDao dao = new PersonDao();
      String keyword = request.getParameter("q");
      keyword = new String(keyword.getBytes("iso8859-1"),"utf-8");
      List list = dao.getPersonAutoData(keyword);
      writeJsonReuslt(response, list != null ? JSON.toJSONString(list) : "");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}